home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / text / faqs / lisp-faq.part2 < prev    next >
Encoding:
Internet Message Format  |  1994-05-15  |  45.9 KB

  1. Subject: FAQ: Lisp Frequently Asked Questions 2/7 [Monthly posting]
  2. Newsgroups: comp.lang.lisp,news.answers,comp.answers
  3. From: mkant+@cs.cmu.edu (Mark Kantrowitz)
  4. Date: Fri, 13 May 1994 14:51:26 GMT
  5.  
  6. Archive-name: lisp-faq/part2
  7. Last-Modified: Thu May 12 21:32:47 1994 by Mark Kantrowitz
  8. Version: 1.45
  9.  
  10. ;;; ****************************************************************
  11. ;;; Answers to Frequently Asked Questions about Lisp ***************
  12. ;;; ****************************************************************
  13. ;;; Written by Mark Kantrowitz and Barry Margolin
  14. ;;; lisp_2.faq -- 47146 bytes
  15.  
  16. This post contains Part 2 of the Lisp FAQ.
  17.  
  18. If you think of questions that are appropriate for this FAQ, or would
  19. like to improve an answer, please send email to us at lisp-faq@think.com.
  20.  
  21. Topics Covered (Part 2):
  22.  
  23.   [2-1]   Is there a GNU-Emacs interface to Lisp?
  24.   [2-2]   When should I use a hash table instead of an association list?
  25.   [2-3]   What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  26.   [2-4]   Is Lisp inherently slower than more conventional languages such as C?
  27.   [2-5]   Why does Common Lisp have "#'"?
  28.   [2-6]   How do I call non-Lisp functions from Lisp?
  29.   [2-7]   Can I call Lisp functions from other languages?
  30.   [2-8]   I want to call a function in a package that might not exist at
  31.           compile time. How do I do this?  
  32.   [2-9]   What is CDR-coding?
  33.   [2-10]  What is garbage collection?
  34.   [2-11]  How do I save an executable image of my loaded Lisp system?
  35.           How do I run a Unix command in my Lisp?
  36.   [2-12]  I'm porting some code from a Symbolics Lisp machine to some
  37.           other platform, and there are strange characters in the code.
  38.           What do they mean?  
  39.   [2-13]  History: Where did Lisp come from?
  40.   [2-14]  How do I find the argument list of a function?
  41.           How do I get the function name from a function object?
  42.   [2-15]  How can I have two Lisp processes communicate via unix sockets?
  43.   [2-16]  How can I create a stream that acts like UNIX's /dev/null
  44.           (i.e., gobbles any output and immediately signals EOF on
  45.           input operations)?
  46.   [2-17]  Read-time conditionalization of code (#+ #- and *features*)   
  47.   [2-18]  What reader macro characters are used in major Lisp systems?
  48.   [2-19]  How do I determine if a file is a directory or not? 
  49.           How do I get the current directory name from within a Lisp 
  50.           program? Is there any way to create a directory?
  51.   [2-20]  What is a "Lisp Machine" (LISPM)?
  52.  
  53. Search for \[#\] to get to question number # quickly.
  54.  
  55. ----------------------------------------------------------------
  56. Subject: [2-1] Is there a GNU-Emacs interface to Lisp?
  57.  
  58. ILISP is a powerful GNU-Emacs interface to many dialects of Lisp,
  59. including Lucid, Allegro, {A}KCL, IBCL, and CMU. Written by Chris
  60. McConnell <ccm+@cs.cmu.edu> and now maintained by Ivan Vazquez
  61. <ivan@haldane.bu.edu>. It is available by anonymous ftp from
  62.    haldane.bu.edu:/pub/ilisp/ [128.197.54.25] 
  63. as the file ilisp.tar.Z. If you want to be on the ilisp mailing list,
  64. to hear about new releases and patches, send mail to
  65. ilisp-request@darwin.bu.edu Please send any comments or code to
  66. ilisp@darwin.bu.edu. Bugs should be sent to ilisp-bug@darwin.bu.edu
  67. (or ilisp-bugs@darwin.bu.edu).
  68.  
  69. Franz Inc.'s GNU-Emacs/Lisp interface includes an online Common Lisp
  70. manual. (The manual is available by license from Franz Inc. Contact
  71. info@franz.com for more information.) The Emacs-Lisp interface
  72. (without the online Common Lisp reference manual and some
  73. Allegro-specific code) is available free from
  74.    ftp.uu.net:/vendor/franz/emacs/eli-2.0.11.tar.gz
  75. and takes advantage of GNU-Emacs 19.X's newest features, including
  76. support for mouse input, pulldown menus, and multifont text. The
  77. interface also supports Epoch 3.2 and 4.2, and LEmacs 19.6 and 19.8.
  78. For discussion of the Franz lisp-emacs interface, join the
  79. allegro-cl-request@ucbvax.berkeley.edu mailing list.
  80. (See also [1-2] for a hardcopy version of the Common Lisp reference manual.)
  81.  
  82. The cl-shell package provides a major mode (cl-shell-mode) for running
  83. Common Lisp (CL) as an Emacs subprocess.  It provides a general
  84. mechanism for communication between CL and Emacs which does not rely
  85. on extra processes, and should therefore be easily portable to any
  86. version of CL.  Features include direct (i.e., not through a temp file)
  87. evaluation and in-package compilation of forms from lisp-mode buffers,
  88. type-ahead and a history mechanism for the cl-shell buffer, and pop-up
  89. help facilities for the CL functions documentation, macroexpand and
  90. describe.  Extensions for Lucid Common Lisp provide pop-up arglists
  91. and source file editing.  Other extensions are provided to allow
  92. editing source files of CLOS or Flavors methods.  Cl-shell is
  93. available on the Lucid tape (in the goodies directory) or via
  94. anonymous ftp from whitechapel.media.mit.edu (18.85.0.125).
  95.  
  96. Lucid includes some other Emacs-Lisp interfaces in its goodies directory.
  97.  
  98. Harlequin's LispWorks includes an Emacs-Lisp interface.
  99.  
  100. Venue's Medley has an optional EMACS Interface.
  101.  
  102. GNU-Emacs itself is available by anonymous ftp from prep.ai.mit.edu.
  103.  
  104. Edebug, a debugger for Emacs Lisp, and some utilities for Common Lisp
  105. debugging (Dave Gillespie's version of cl.el) are available by
  106. anonymous ftp from 
  107.    a.cs.uiuc.edu:/pub/edebug/
  108. To join the Edebug mailing list edebug@cs.uiuc.edu send mail to 
  109. edebug-request@cs.uiuc.edu. For more information, write to Daniel
  110. LaLiberte <liberte@cs.uiuc.edu>. 
  111.  
  112. ----------------------------------------------------------------
  113. Subject: [2-2] When should I use a hash table instead of an association list?
  114.  
  115. Both association lists (alists) and hash tables may be used to
  116. represent tabular data. Hash tables have an O(1) running time and
  117. alists an O(n) running time, so hash tables are ultimately more
  118. efficient than alists. However, if the alists are small, they can be
  119. more efficient than hash tables, which have a large initial overhead.
  120.  
  121. Alists can sometimes be more efficient if the keys are sorted
  122. according to frequency, with the most heavily accessed keys appearing
  123. at the front of the list. But one doesn't always know this kind of
  124. information, and even then the frequency distribution may be flat.
  125.  
  126. In Allegro CL 4.1 [SPARC; R1], the rule of thumb is that for less than
  127. 24 elements, linear search using alists beats hashing.  In Lucid CL
  128. 4.0.1 HP 9000/700, the break-even point is at 10 elements. The
  129. break-even points vary in other lisps from as low as 4 elements to as
  130. high as 100 elements. So if you're using alists in your code, using 
  131. hash tables instead may speed up your program. 
  132.  
  133. A potential problem may occur, however, when the keys of an EQ or EQL
  134. hash table are Lisp objects such as conses or arrays (or other objects
  135. that are identified by their addresses). In most implementations, such
  136. tables must be re-hashed after garbage collection. If your application
  137. causes frequent GCs, this can adversely affect the performance of hash
  138. table lookup. Since EQL-hashing and =-hashing of fixnums generally
  139. don't require rehashing after GC, one way of avoiding this problem is
  140. to include a unique identifier in each key object and hash on that
  141. instead. Another solution is to use an EQUAL hash table if the keys
  142. are conses or an EQUALP hash table if the keys are arrays or other
  143. (non-circular!) structures.
  144.  
  145. ----------------------------------------------------------------
  146. Subject: [2-3] What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  147.  
  148. Hopefully, the only reason you need to do this is as part of trying to port
  149. some old MacLisp code to Common Lisp.  These functions predated the
  150. inclusion of strings as a first-class data type in Lisp; symbols were used
  151. as strings, and they ere EXPLODEd to allow the individual characters to be
  152. manipulated in a list.
  153.  
  154. Probably the best approximations of these are:
  155.  
  156.    (defun explode (object)
  157.      (loop for char across (prin1-to-string object)
  158.            collect (intern (string char))))
  159.  
  160.    (defun implode (list)
  161.      (read-from-string (coerce (mapcar #'character list) 'string)))
  162.  
  163. An alternate definition of EXPLODE which uses MAP instead of LOOP is:
  164.  
  165.    (defun explode (object)
  166.      (map 'list #'(lambda (char) 
  167.                     (intern (string char)))
  168.           (prin1-to-string object)))
  169.  
  170. The creation of N conses of garbage to process a string of N
  171. characters is a hideously inefficient way of doing the job.  Rewrite
  172. EXPLODE code with PRIN1-TO-STRING, or better STRING if the arguments
  173. are symbols without funny characters.  For IMPLODE, try to make its
  174. caller use strings and try to make the result usable as a string to
  175. avoid having to call INTERN or READ-FROM-STRING.
  176.  
  177. ----------------------------------------------------------------
  178. Subject: [2-4] Is Lisp inherently slower than more conventional languages
  179.                such as C?
  180.  
  181. This is a tough question to answer, as you probably expected.  In many
  182. cases, it appears to be.  Lisp does not require the programmer to specify
  183. the data type of variables, so generic arithmetic operators may have to
  184. perform type checking at runtime in order to determine how to proceed.
  185. However, Lisp code can also be denser (i.e.  there is more expressed in a
  186. single line) than many other languages: the Lisp expression (+ A B) is more
  187. powerful than the C expression A+B (the Lisp version supports bignums,
  188. rationals, and complex numbers, while the C version only supports
  189. limited-size integers and floating point); therefore, one may claim that it
  190. is reasonable that the Lisp version take longer than the C version (but
  191. don't expect everyone to accept this rationalization).  Solutions to this
  192. include hardware support (e.g. processors that support type tags in data,
  193. such as SPARC and Symbolics Lisp Machines), declarations, and specialized
  194. variants of functions (e.g. in MacLisp, + accepts and returns only fixnums,
  195. +$ accepts and returns only flonums, and PLUS is generic).
  196.  
  197. At one time, the MIT PDP-10 MacLisp compiler was compared to DEC's
  198. PDP-10 Fortran compiler.  When appropriate declarations were supplied
  199. in the Lisp code, the performance of compiled Lisp arithmetic rivaled
  200. that of the Fortran code.  It would hardly be fair to compare Lisp
  201. without declarations to Fortran, since the Fortran compiler would have
  202. more information upon which it could base its optimizations. A more
  203. recent test found that numeric code compiled with optimizations using
  204. CMU CL is within the same ballpark as highly optimized Fortran code.
  205. For unoptimized Fortran code, CMU CL was about 4 times faster.
  206. Even the speed of numeric code generated by other Lisp compilers
  207. (AKCL, Allegro, Lucid) was well within an order of magnitude of good
  208. Fortran and C compilers (although slower than CMU CL).  Inspection of
  209. the emitted C code from AKCL doesn't reveal many obvious sources of
  210. inefficiency. (Since AKCL compiles Lisp into C, there are many cases
  211. where KCL code is as fast as hand-written C code.)
  212.  
  213. See the paper peoplesparc.berkeley.edu:/pub/papers/fastlisp.ps.Z
  214. for a discussion of the speed of Lisp vis a vis Fortran or C.
  215.  
  216. Since Lisp is a good language for rapid prototyping, it is easy for a
  217. mediocre programmer (or even a good programmer, who isn't being careful) to
  218. generate a large amount of inefficient Lisp code. A good example is the use
  219. of APPEND to link successive lists together, instead of keeping a pointer
  220. to the tail of the list. Often a programmer can obtain significant
  221. speed increases by using a time/space profiler to identify the
  222. functions which waste time (often small functions which are called
  223. frequently) and rewriting those functions.
  224.      
  225. ----------------------------------------------------------------
  226. Subject: [2-5] Why does Common Lisp have "#'"?
  227.  
  228. #' is a macro-character which expands #'FOO to (FUNCTION FOO).  Symbols in
  229. Lisp have two bindings, one for values and one for functions, allowing them
  230. to represent both variables and functions, depending on context. #'FOO
  231. accesses FOO's lexical function binding in a context where the value
  232. interpretation would normally occur.  #' is also used to create lexical
  233. closures for lambda expressions. A lexical closure is a function which when
  234. invoked executes the body of the lambda-expression in the lexical
  235. environment within which the closure was created.  See pp. 115-117 of CLtL2
  236. for more details.
  237.  
  238. ----------------------------------------------------------------
  239. Subject: [2-6] How do I call non-Lisp functions from Lisp?
  240.  
  241. Most Lisp implementations for systems where Lisp is not the most common
  242. language provide a "foreign function" interface.  As of now there has been
  243. no significant standardization effort in this area.  They tend to be
  244. similar, but there are enough differences that it would be inappropriate to
  245. try to describe them all here.  In general, one uses an
  246. implementation-dependent macro that defines a Lisp function, but instead of
  247. supplying a body for the function, one supplies the name of a function written
  248. in another language; the argument list portion of the definition is
  249. generally augmented with the data types the foreign function expects and
  250. the data type of the foreign function's return value, and the Lisp
  251. interface function arranges to do any necessary conversions.  There is also
  252. generally a function to "load" an object file or library compiled in a
  253. foreign language, which dynamically links the functions in the file being
  254. loaded into the address space of the Lisp process, and connects the
  255. interface functions to the corresponding foreign functions.
  256.  
  257. If you need to do this, see the manual for your language implementation for
  258. full details.  In particular, be on the lookout for restrictions on the
  259. data types that may be passed.  You may also need to know details about the
  260. linkage conventions that are used on your system; for instance, many C
  261. implementations prepend an underscore onto the names of C functions when
  262. generating the assembler output (this allows them to use names without
  263. initial underscores internally as labels without worrying about conflicts),
  264. and the foreign function interface may require you to specify this form
  265. explicitly.
  266.  
  267. Franz Allegro Common Lisp's "Foreign Function Call Facility" is
  268. described in chapter 10 of the documentation. Calling Lisp Functions
  269. from C is treated in section 10.8.2. The foreign function interface in
  270. Macintosh Common Lisp is similar. The foreign function interface for
  271. KCL is described in chapter 10 of the KCL Report. The foreign function
  272. interfaces for Lucid on the Vax and Lucid on the Sun4 are
  273. incompatible. Lucid's interface is described in chapter 5 of the
  274. Advanced User's Guide.
  275.  
  276. ----------------------------------------------------------------
  277. Subject: [2-7] Can I call Lisp functions from other languages?
  278.  
  279. In implementations that provide a foreign function interface as described
  280. above, there is also usually a "callback" mechanism.  The programmer may
  281. associate a foreign language function name with a Lisp function.  When a
  282. foreign object file or library is loaded into the Lisp address space, it is
  283. linked with these callback functions.  As with foreign functions, the
  284. programmer must supply the argument and result data types so that Lisp may
  285. perform conversions at the interface. Note that in such foreign function
  286. interfaces Lisp is often left "in control" of things like memory
  287. allocation, I/O channels, and startup code (this is a major nuisance
  288. for lots of people).
  289.      
  290. ----------------------------------------------------------------
  291.  
  292. Subject: [2-8]  I want to call a function in a package that might not exist at
  293.                 compile time. How do I do this?
  294.  
  295. Use (funcall (find-symbol "SYMBOL-NAME" :pkg-name) ...).
  296.  
  297. ----------------------------------------------------------------
  298. Subject: [2-9]  What is CDR-coding?
  299.  
  300. CDR-coding is a space-saving way to store lists in memory.  It is normally
  301. only used in Lisp implementations that run on processors that are
  302. specialized for Lisp, as it is difficult to implement efficiently
  303. in software.  In normal list structure, each element of the
  304. list is represented as a CONS cell, which is basically two pointers (the
  305. CAR and CDR); the CAR points to the element of the list, while the CDR
  306. points to the next CONS cell in the list or NIL.  CDR-coding takes
  307. advantage of the fact that most CDR cells point to another CONS, and
  308. further that the entire list is often allocated at once (e.g. by a call to
  309. LIST).  Instead of using two pointers to implement each CONS cell, the CAR
  310. cell contains a pointer and a two-bit "CDR code".  The CDR code may contain
  311. one of three values: CDR-NORMAL, CDR-NEXT, and CDR-NIL.  If the code is
  312. CDR-NORMAL, this cell is the first half of an ordinary CONS cell pair, and
  313. the next cell in memory contains the CDR pointer as described above.  If
  314. the CDR code is CDR-NEXT, the next cell in memory contains the next CAR
  315. cell; in other words, the CDR pointer is implicitly thisaddress+1, where
  316. thisaddress is the memory address of the CAR cell.  If the CDR code is
  317. CDR-NIL, then this cell is the last element of the list; the CDR pointer is
  318. implicitly a reference to the object NIL.  When a list is constructed
  319. incrementally using CONS, a chain of ordinary pairs is created; however,
  320. when a list is constructed in one step using LIST or MAKE-LIST, a block of
  321. memory can be allocated for all the CAR cells, and their CDR codes all set
  322. to CDR-NEXT (except the last, which is CDR-NIL), and the list will only
  323. take half as much storage (because all the CDR pointers are implicit).
  324.  
  325. If this were all there were to it, it would not be difficult to implement
  326. in software on ordinary processors; it would add a small amount of overhead
  327. to the CDR function, but the reduction in paging might make up for it.  The
  328. problem arises when a program uses RPLACD on a CONS cell that has a CDR
  329. code of CDR-NEXT or CDR-NIL.  Normally RPLACD simply stores into the CDR
  330. cell of a CONS, but in this case there is no CDR cell -- its contents are
  331. implicitly specified by the CDR code, and the word that would normally
  332. contain the CDR pointer contains the next CONS cell (in the CDR-NEXT case)
  333. to which other data structures may have pointers, or the first word of some
  334. other object (in the CDR-NIL case).  When CDR-coding is used, the
  335. implementation must also provide automatic "forwarding pointers"; an
  336. ordinary CONS cell is allocated, the CAR of the original cell is copied
  337. into its CAR, the value being RPLACD'ed is stored into its CDR, and the old
  338. CAR cell is replaced with a forwarding pointer to the new CONS cell.
  339. Whenever CAR or CDR is performed on a CONS, it must check whether the
  340. location contains a forwarding pointer.  This overhead on both CAR and CDR,
  341. coupled with the overhead on CDR to check for CDR codes, is generally
  342. enough that using CDR codes on conventional hardware is infeasible.
  343.  
  344. There is some evidence that CDR-coding doesn't really save very much
  345. memory, because most lists aren't constructed at once, or RPLACD is done on
  346. them enough that they don't stay contiguous.  At best this technique can
  347. save 50% of the space occupied by CONS cells. However, the savings probably
  348. depends to some extent upon the amount of support the implementation
  349. provides for creating CDR-coded lists.  For instance, many system functions
  350. on Symbolics Lisp Machines that operate on lists have a :LOCALIZE option;
  351. when :LOCALIZE T is specified, the list is first modified and then copied
  352. to a new, CDR-coded block, with all the old cells replaced with forwarding
  353. pointers.  The next time the garbage collector runs, all the forwarding
  354. pointers will be spliced out.  Thus, at a cost of a temporary increase in
  355. memory usage, overall memory usage is generally reduced because more lists
  356. may be CDR-coded. There may also be some benefit in improved paging
  357. performance due to increased locality as well (putting a list into
  358. CDR-coded form makes all the "cells" contiguous). Nevertheless, modern
  359. Lisps tend to use lists much less frequently, with a much heavier
  360. reliance upon code, strings, and vectors (structures).
  361.  
  362. ----------------------------------------------------------------
  363. Subject: [2-10] What is garbage collection?
  364.  
  365. Garbage Collection (GC) refers to the automatic storage allocation
  366. mechanisms present in many Lisps. There are several kinds of storage
  367. allocation algorithms, but most fall within two main classes:
  368.  
  369.    1. Stop and Copy. Systems which copy active objects from "old"
  370.       storage to "new" storage and then recycle the old storage.
  371.  
  372.    2. Mark and Sweep. Systems which link together storage
  373.       used by discarded objects. 
  374.  
  375. Generational scavenging garbage collection (aka emphemeral GC) is a
  376. variation in which memory is allocated in layers, with tenured
  377. (long-lived) objects in the older layers. Rather than doing a full GC
  378. of all of memory every time more room is needed, only the last few
  379. layers are GCed during an ephemeral GC, taking much less time.
  380. Short-lived objects are quickly recycled, and full GCs are then much
  381. less frequent. It is most often used to improve the performance of
  382. stop and copy garbage collectors.  It is possible to implement
  383. ephemeral GC in mark and sweep systems, just much more difficult.
  384.  
  385. Stop and copy garbage collection provides simpler storage allocation,
  386. avoids fragmentation of memory (intermixing of free storage with used
  387. storage). Copying, however, consumes more of the address space, since up to
  388. half the space must be kept available for copying all the active objects.
  389. This makes stop and copy GC impractical for systems with a small address
  390. space or without virtual memory.  Also, copying an object requires that you
  391. track down all the pointers to an object and update them to reflect the new
  392. address, while in a non-copying system you need only keep one pointer to an
  393. object, since its location will not change. It is also more difficult to
  394. explicitly return storage to free space in a copying system.
  395.  
  396. Garbage collection is not part of the Common Lisp standard. Most Lisps
  397. provide a function ROOM which provides human-readable information about the
  398. state of storage usage. In many Lisps, (gc) invokes an ephemeral garbage
  399. collection, and (gc t) a full garbage collection.
  400.  
  401. ----------------------------------------------------------------
  402. Subject: [2-11] How do I save an executable image of my loaded Lisp system?
  403.                 How do I run a Unix command in my Lisp?
  404.  
  405. There is no standard for dumping a Lisp image. Here are the
  406. commands from some lisp implementations:
  407.    Lucid:               DISKSAVE
  408.    Symbolics:           Save World  [CP command]
  409.    CMU CL:              SAVE-LISP
  410.    Franz Allegro:       EXCL:DUMPLISP (documented) 
  411.                         SAVE-IMAGE (undocumented)
  412.    Medley:              IL:SYSOUT or IL:MAKESYS
  413.    MCL:                 SAVE-APPLICATION <pathname>
  414.                           &key :toplevel-function  :creator :excise-compiler
  415.                           :size :resources :init-file :clear-clos-caches
  416.    KCL:                 (si:save-system "saved_kcl")
  417.    LispWorks:        LW:SAVE-IMAGE
  418.  
  419. There is no standard for running a Unix shell command from Lisp,
  420. especially since not all Lisps run on top of Unix. Here are the
  421. commands from some Lisp implementations:
  422.    Allegro:             EXCL:RUN-SHELL-COMMAND
  423.    Lucid:               RUN-PROGRAM (name 
  424.                                      &key input output
  425.                                           error-output (wait t) arguments
  426.                                           (if-input-does-not-exist :error)
  427.                                           (if-output-exists :error)
  428.                                           (if-error-output-exists :error))
  429.    KCL:                 SYSTEM 
  430.                         For example, (system "ls -l").
  431.                         You can also try RUN-PROCESS and EXCLP, but they
  432.                         don't work with all versions of KCL.
  433.    CMU CL:              RUN-PROGRAM (program args
  434.                &key (env *environment-list*) (wait t) pty input
  435.                if-input-does-not-exist output
  436.                (if-output-exists :error) (error :output) 
  437.                (if-error-exists :error) status-hook before-execve)
  438.    LispWorks:           FOREIGN:CALL-SYSTEM-SHOWING-OUTPUT
  439.  
  440. To toggle source file recording and cross-reference annotations, use
  441.    Allegro:             excl:*record-source-file-info*
  442.             excl:*load-source-file-info* 
  443.             excl:*record-xref-info*
  444.             excl:*load-xref-info*
  445.    LispWorks:           (toggle-source-debugging nil)
  446.  
  447. Memory management:
  448.    CMU CL:              (bytes-consed-between-gcs)  [this is setfable]
  449.    Lucid:        (change-memory-management 
  450.                      &key growth-limit expand expand-reserved)
  451.    Allegro:        *tenured-bytes-limit*
  452.    LispWorks:           LW:GET-GC-PARAMETERS
  453.                         (use LW:SET-GC-PARAMETERS to change them)
  454.  
  455. ----------------------------------------------------------------
  456. Subject: [2-12] I'm porting some code from a Symbolics Lisp machine to some
  457.                 other platform, and there are strange characters in the code.
  458.                 What do they mean?
  459.  
  460. The Symbolics Zetalisp character set includes the following
  461. characters not present in other Lisps (^ means control):
  462.    ^]      >=      greater than or equal to
  463.    ^\      <=      less than or equal to
  464.    ^Z      !=      not equal to
  465.    ^^      ==      equivalent to 
  466.    ^E      not
  467.    ^G      pi
  468.    ^L      +/-     plus/minus
  469.    ^H      lambda
  470.    ^F      epsilon
  471.    ^W      <-->    left/right arrow
  472.    ^X      <--     left arrow
  473.    ^Y      -->     right arrow
  474.    ^A              down arrow
  475.    ^K              up arrow
  476.    ^D              up caret
  477.    ^_              down caret
  478.    ^T              forall
  479.    ^U              there exists
  480.    ^B              alpha
  481.    ^C              beta
  482.    ^I              gamma
  483.    ^J              delta
  484.    ^O              partial delta  
  485.    ^N              infinity
  486.    ^M              circle +
  487.    ^V              circle x
  488.  
  489. Other special characters to look out for are the font-change characters,
  490. which are represented as a ^F followed by a digit or asterisk. A digit
  491. means to push font #N onto the stack; an asterisk means to pop the most
  492. recent font from the stack. You can clean up the code by replacing "\^F."
  493. with "". In format statements, ^P and ^Q are used to delimit text to
  494. be printed in a particular character style.
  495.      
  496. ----------------------------------------------------------------
  497. Subject: [2-13] History: Where did Lisp come from?
  498.  
  499. John McCarthy developed the basics behind Lisp during the 1956 Dartmouth
  500. Summer Research Project on Artificial Intelligence.  He intended it as an
  501. algebraic LISt Processing (hence the name) language for artificial
  502. intelligence work. Early implementations included the IBM 704, the IBM
  503. 7090, the DEC PDP-1, the DEC PDP-6 and the DEC PDP-10. The PDP-6 and
  504. PDP-10 had 18-bit addresses and 36-bit words, allowing a CONS cell to
  505. be stored in one word, with single instructions to extract the CAR and
  506. CDR parts. The early PDP machines had a small address space, which
  507. limited the size of Lisp programs. 
  508.  
  509. Milestones in the development of Lisp:
  510.  
  511.    1956            Dartmouth Summer Research Project on AI.
  512.  
  513.    1960-65         Lisp1.5 is the primary dialect of Lisp.
  514.  
  515.    1964-           Development of BBNLisp at BBN.
  516.  
  517.    late 60s        Lisp1.5 diverges into two main dialects:
  518.                    Interlisp (originally BBNLisp) and MacLisp.
  519.  
  520.    early 70s       Development of special-purpose computers known as Lisp
  521.                    Machines, designed specificly to run Lisp programs. 
  522.                    Xerox D-series Lisp Machines run Interlisp-D. 
  523.                    Early MIT Lisp Machines run Lisp Machine Lisp 
  524.                    (an extension of MacLisp).
  525.  
  526.    1969            Anthony Hearn and Martin Griss define Standard Lisp to
  527.                    port REDUCE, a symbolic algebra system, to a variety
  528.                    of architectures.  
  529.  
  530.    late 70s        Macsyma group at MIT developed NIL (New Implementation
  531.                    of Lisp), a Lisp for the VAX.
  532.  
  533.                    Stanford and Lawrence Livermore National Laboratory
  534.                    develop S-1 Lisp for the Mark IIA supercomputer.
  535.  
  536.                    Franz Lisp (dialect of MacLisp) runs on stock-hardware
  537.                    Unix machines.
  538.  
  539.                    Gerald J. Sussman and Guy L. Steele developed Scheme,
  540.                    a simple dialect of Lisp with lexical scoping and
  541.                    lexical closures, continuations as first-class objects,
  542.                    and a simplified syntax (i.e., only one binding per symbol).
  543.  
  544.                    Advent of object-oriented programming concepts in Lisp.
  545.                    Flavors was developed at MIT for the Lisp machine,
  546.                    and LOOPS (Lisp Object Oriented Programming System) was
  547.                    developed at Xerox. 
  548.  
  549.    early 80s       Development of SPICE-Lisp at CMU, a dialect of MacLisp
  550.                    designed to run on the Scientific Personal Integrated
  551.                    Computing Environment (SPICE) workstation.
  552.  
  553.    1980            First biannual ACM Lisp and Functional Programming Conf.
  554.  
  555.    1981            PSL (Portable Standard Lisp) runs on a variety of platforms.
  556.  
  557.    1981+           Lisp Machines from Xerox, LMI (Lisp Machines Inc) 
  558.                    and Symbolics available commercially.
  559.  
  560.    April 1981      Grass roots definition of Common Lisp as a description
  561.                    of the common aspects of the family of languages (Lisp
  562.                    Machine Lisp, MacLisp, NIL, S-1 Lisp, Spice Lisp, Scheme). 
  563.                    
  564.  
  565.    1984            Publication of CLtL1. Common Lisp becomes a de facto 
  566.                    standard.
  567.  
  568.    1986            X3J13 forms to produce a draft for an ANSI Common Lisp
  569.                    standard. 
  570.  
  571.    1987            Lisp Pointers commences publication.
  572.  
  573.    1990            Steele publishes CLtL2 which offers a snapshot of
  574.                    work in progress by X3J13.  (Unlike CLtL1, CLtL2
  575.                    was NOT an output of the standards process and was
  576.                    not intended to become a de facto standard.  Read
  577.                    the Second Edition Preface for further explanation
  578.                    of this important issue.) Includes CLOS,
  579.                    conditions, pretty printing and iteration facilities. 
  580.  
  581.    1992            X3J13 creates a draft proposed American National
  582.                    Standard for Common Lisp. This document is the
  583.                    first official successor to CLtL1. 
  584.  
  585. [Note: This summary is based primarily upon the History section of the
  586. draft ANSI specification. More detail and references can be obtained from
  587. that document. See [4-12] for information on obtaining a copy.]
  588.  
  589. Gabriel and Steele's "The Evolution of Lisp", which appeared in the
  590. 1993 ACM History of Programming Languages conference, is available by
  591. anonymous ftp from  
  592.    ftp.cs.umbc.edu:/pub/Memoization/Misc/    [130.85.100.53]
  593. as Evolution-of-Lisp.ps.Z. 
  594.  
  595. ----------------------------------------------------------------
  596. Subject: [2-14]  How do I find the argument list of a function?
  597.                  How do I get the function name from a function object?
  598.  
  599. There is no standard way to find the argument list of a function,
  600. since implementations are not required to save this information.
  601. However, many implementations do remember argument information, and
  602. usually have a function that returns the lambda list. Here are the
  603. commands from some Lisp implementations:
  604.  
  605.    Lucid:                               arglist
  606.    Allegro:                             excl::arglist
  607.    Symbolics:                           arglist
  608.    LispWorks:                           lw:function-lambda-list
  609.  
  610. CMU Common Lisp, new compiler:
  611.    #+(and :CMU :new-compiler)
  612.    (defun arglist (name)
  613.      (let* ((function (symbol-function name))
  614.             (stype (system:%primitive get-vector-subtype function)))
  615.        (when (eql stype system:%function-entry-subtype)
  616.          (cadr (system:%primitive header-ref function
  617.                                   system:%function-entry-type-slot)))))
  618.  
  619. The draft ANSI standard does include FUNCTION-LAMBDA-EXPRESSION and
  620. FUNCTION-KEYWORDS, which can be used to create an ARGLIST function.
  621.  
  622. If you're interested in the number of required arguments you could use
  623.  
  624.    (defun required-arguments (name)
  625.      (or (position-if #'(lambda (x) (member x lambda-list-keywords))
  626.                       (arglist name))
  627.          (length (arglist name))))
  628.  
  629. To extract the function name from the function object, as in
  630.         (function-name #'car) ==> 'car
  631. use the following vendor-dependent functions:
  632.  
  633.    Symbolics: (si::compiled-function-name <fn>)
  634.     (unless (si:lexical-closure-p <fn>) ...)
  635.    Lucid:     (sys::procedure-ref <fn> SYS:PROCEDURE-SYMBOL)
  636.     (when (sys:procedurep <fn>) ..)
  637.    Allegro:   (xref::object-to-function-name <fn>)
  638.    CMU CL:    (kernel:%function-header-name <fn>)
  639.    AKCL:      (system::compiled-function-name <fn>)
  640.    MCL:       (ccl::function-name <fn>)
  641.    Harlequin: (system::function-name <fn>)
  642.  
  643. If a vendor-dependent function does not exist, the following
  644. (inefficient) code maps over all symbols looking for one whose
  645. function-cell matches the function object.
  646.  
  647. (defun function-name (fobject)
  648.    (do-all-symbols (fsymbol)
  649.       (when (and (fboundp fsymbol)
  650.                  (eq (symbol-function fsymbol) fobject))
  651.         (return fsymbol))))
  652.  
  653. If a vendor supports FUNCTION-LAMBDA-EXPRESSION, the third value is
  654. the name of the function, if available. 
  655.  
  656. ----------------------------------------------------------------
  657. Subject: [2-15] How can I have two Lisp processes communicate via unix sockets?
  658.  
  659. CLX uses Unix sockets to communicate with the X window server. Look at
  660. the following files from the CLX distribution for a good example of
  661. using Unix sockets from Lisp:
  662.         defsystem.lisp          Lucid, AKCL, IBCL, CMU.
  663.         socket.c, sockcl.lisp   AKCL, IBCL
  664.         excldep.lisp            Franz Allegro CL
  665. You will need the "socket.o" files which come with Lucid and Allegro.
  666. To obtain CLX, see the entry for CLX in the answer to question [7-1].
  667.  
  668. See the file sockets.tar.gz in the Lisp Utilities repository
  669. described in the answer to question [6-1].
  670.  
  671. ----------------------------------------------------------------
  672. Subject: [2-16]  How can I create a stream that acts like UNIX's /dev/null
  673.                  (i.e., gobbles any output and immediately signals EOF on
  674.                  input operations)?
  675.  
  676. (defparameter *dev-null*
  677.   #-lispm
  678.   (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream))
  679.   ;; Since Lisp Machines have a built-in /dev/null which handles
  680.   ;; additional, non-standard operations, we'll use that instead.
  681.   #+lispm #'system:null-stream)
  682.  
  683. ----------------------------------------------------------------
  684. Subject: [2-17] Read-time conditionalization of code (#+ #- and *features*)
  685.  
  686. The #+ and #- syntax provides for the read-time conditionalization of
  687. lisp code, depending on the presence or absence of keywords on the
  688. *features* list. The nascent Common Lisp standard does not specify
  689. what keywords an implementation must have on its features list.
  690. Nevertheless, most implementations have features that allow one to
  691. distinguish the implementation from other implementations. This allows
  692. one to write implementation-dependent code that is run only in the
  693. relevant implementations.
  694.  
  695. Here is a list of the features to use to specify a particular Common
  696. Lisp implementation. Unfortunately, not every vendor has a
  697. unique keyword that distinguishes their family of implementations from
  698. those of other vendors, nor major and minor versions of the implementation.
  699.  
  700.    :lucid                       Lucid Common Lisp
  701.    :lcl3.0                      Lucid Common Lisp v3.0 and above
  702.    :lcl4.0                      Lucid Common Lisp v4.0 and above
  703.    ----------------
  704.    (and :allegro :franz-inc)    Franz Allegro Common Lisp
  705.    :excl                        Franz Allegro Common Lisp 
  706.    :aclpc                       Franz Allegro Common Lisp\PC.
  707.    :allegro-v3.0                Franz Allegro Common Lisp v3.0 
  708.    :allegro-v3.1                Franz Allegro Common Lisp v3.1 
  709.    :allegro-v4.0                Franz Allegro Common Lisp v4.0 
  710.    :allegro-v4.1                Franz Allegro Common Lisp v4.1 
  711.    ----------------
  712.    :cmu                         CMU Common Lisp
  713.    (and :cmu :new-compiler)     CMU Common Lisp w/Python compiler
  714.    (and :cmu :python)           CMU Common Lisp w/Python compiler
  715.    :cmu17                       CMU Common Lisp v17 and above
  716.    ----------------
  717.    kcl                          Kyoto Common Lisp
  718.    akcl                         Austin KCL
  719.    :ibcl                        Ibuki Common Lisp 
  720.    ----------------
  721.    :mcl                         Macintosh Common Lisp
  722.    :coral                       Coral Lisp; bought by Apple to become
  723.                 MACL, then MCL
  724.    :ccl                         Coral Common Lisp
  725.     [Note: Harlequin LispWorks also uses :ccl]
  726.    :ccl-1                       Coral Common Lisp v1
  727.    :ccl-1.3                     Coral Common Lisp v1.3 and higher
  728.    :ccl-2                       present in Macintosh Common Lisp 2.0 and higher
  729.    ----------------
  730.    :harlequin-common-lisp       Harlequin Common Lisp
  731.    :harlequin-unix-lisp         Harlequin on Unix platforms
  732.    :harlequin-PC-lisp           Harlequin on PC platforms
  733.    :lispworks                   Harlequin Lispworks development environment
  734.    :lispworks3                  major release of Harlequin Lispworks
  735.    :lispworks3.1                major and minor release of Harlequin Lispworks
  736.    :harlequin                   All Harlequin products. not always present?
  737.    ----------------
  738.    :clisp                       CLISP Common Lisp
  739.    ----------------
  740.    :symbolics                   Symbolics Genera
  741.    :imach                       Symbolics Genera for Ivory architecture
  742.    :cloe-runtime                Symbolics CLOE
  743.    :cloe                        CLOE 3.1
  744.    ----------------
  745.    :procyon                     Procyon Common Lisp
  746.    (and :procyon :macintosh)    Procyon Common Lisp, Macintosh version
  747.    (and :procyon :os2)          Procyon Common Lisp, OS2 version
  748.    ----------------
  749.    :gclisp                      Golden Common Lisp
  750.    ----------------
  751.    (and dec vax common)         DEC VAXlisp
  752.    ----------------
  753.    :explorer                    TI Explorer Lisp Machine  | used
  754.    :TI                          TI Explorer Lisp Machine  | interchangeably
  755.    :elroy                       TI Explorer release 3 and successors
  756.    ----------------
  757.    :Xerox                       Medley (Venue's CL/InterLisp combo) to rel2.01
  758.    :medley                      Medley releases 3.0 and up
  759.       Use  (IL:UNIX-GETPARM "mach") and (IL:UNIX-GETPARM "arch") to
  760.       distinguish platforms under Medley.
  761.    ----------------
  762.    :ecl                         ECoLisp
  763.    ----------------
  764.    :lispm                       Symbolics, TI, and LMI Lisp machines
  765.  
  766.    In the cases where a feature is not a keyword, it is almost always
  767.    in the LISP package.
  768.  
  769. The draft ANSI standard defines some other useful features:
  770.  
  771.   :cltl1                Compatible with the 1st edition of Steele
  772.   :cltl2                Compatible with the 2nd edition of Steele
  773.   :IEEE-Floating-Point  IEEE floating point support
  774.   :X3J13                conforms to some particular draft of the ANSI
  775.                         CL specification 
  776.   :draft-ANSI-CL        conforms to first full public review draft
  777.   :ANSI-CL              conforms to ANSI CL after its adoption
  778.   :common-lisp          language family "Common Lisp"
  779.  
  780. Other features used by some Lisps include:
  781.  
  782.   :clos                 Contains a native CLOS implementation.
  783.   :pcl                  Contains the PCL implementation of CLOS.
  784.   :flavors              Has an implementation of Symbolics Flavors
  785.   :loop                 Contains the :cltl1 version of the Loop macro
  786.   :ansi-loop            Contains the ANSI Loop macro
  787.   :clx or :xlib         Contains CLX
  788.   :clxr4 or :CLX-MIT-R4 Contains CLX for X11R4
  789.   :clxr5 or :CLX-MIT-R5 Contains CLX for X11R5
  790.   :compiler             Contains a compiler  
  791.   :windows              MS Windows version
  792.   :color                Color display
  793.   :monochrome           Monochrome display
  794.   :multiprocessing      Has multiprocessing capabilities.
  795.   :profiler             Has a PC-monitoring based profiler.
  796.  
  797. Platform-specific features, CPU-dependent features, and
  798. operating-system specific features are also important because they can
  799. indicate changes between different implementations of the same lisp,
  800. such as compiled file extensions (e.g., .sbin, .hbin, etc.).
  801. Unfortunately, not every vendor includes such features, and the naming
  802. conventions are inconsistent. Where there are several names for the
  803. same feature, we've put the preferred name first. Hopefully the
  804. vendors will begin to standardize their use of these features.
  805. CPU-dependent features include :sparc (used in CMU CL, Lucid CL,
  806. Harlequin, and Allegro CL), :mips (used in Allegro CL), :r2000 (used
  807. in Allegro CL even on r4000 machines), :mc68000, and :pa (HP's
  808. 9000/800 RISC cpu).  Platform-specific features include :sun (used in
  809. Allegro CL and Lucid), :sun4 (used in CMU CL and Allegro CL), :sgi
  810. (used in Allegro CL), :hp300, :hp400, :hp500, :sun3, :vax, :prime,
  811. :dec, :dec3100, :macintosh (used in Procyon but not MCL), :ibm-pc,
  812. :ibm-rt-pc.  OS-specific features include :unix (used in CMU CL, IBCL,
  813. and Lucid CL), :vms, :sunos (used in CMU CL), :sun-os (used in Lucid),
  814. :sunos4.0 and :sunos4 (used in various Allegro versions independent of
  815. the actual version of SunOS), :mach (used in CMU CL), :hpux, :ultrix,
  816. :os2, and :svr4.
  817.  
  818. Notes:
  819.  
  820.    :allegro alone doesn't suffice to distinguish Franz Allegro Common
  821.    Lisp from Macintosh Allegro Common Lisp (an early version of
  822.    Macintosh Common Lisp). :excl specifies that the EXCL package (a
  823.    set of Allegro extensions to Common Lisp) is present, but this has
  824.    since become synonymous with Franz Allegro Common Lisp.
  825.  
  826.    Thanks to Vincent Keunen for gathering the information in this list.
  827.  
  828. ----------------------------------------------------------------
  829. Subject: [2-18]  What reader macro characters are used in major Lisp systems?
  830.  
  831. The draft ANSI standard for Common Lisp leaves many dispatching macro
  832. characters unassigned. Of these, the following are explicitly reserved
  833. for the user and hence will never be defined by Common Lisp:
  834.    #!, #?, #[, #], #{, and #}. 
  835. All other unassigned macro characters are not reserved for the user,
  836. and hence the user has no guarantee that they won't be used by some
  837. Lisp implementation. 
  838.  
  839. As a result, there is the potential of portability clashes between
  840. systems that use the same macro characters. This question lists the
  841. non-standard macro character usage of major Lisp systems, in an effort
  842. to avoid such conflicts.
  843.  
  844.    #"        AKCL; pathnames
  845.    #$        Macintosh Common Lisp; traps
  846.    #%        Cyc; references to constants in the representation language
  847.    #%        Harlequin Lispworks; ?
  848.    #@        Macintosh Common Lisp; Points notation
  849.    #@         Defsystem    
  850.    #I        Portable Infix Package
  851.    #L        Allegro Common Lisp; logical pathnames
  852.    #M        Series
  853.    #T         Allegro Common Lisp; ?
  854.    #Y        CLISP; ?
  855.    #Z        Series
  856.    #_        Macintosh Common Lisp; traps
  857.    #`        Harlequin Lispworks; ?
  858.  
  859. There is a proposal in the ANSI draft to have COMPILE-FILE and LOAD
  860. bind *READTABLE*, which would allow one to locally redefine syntax
  861. through private readtables. Unfortunately, this doesn't help with the
  862. Infix Package, where one wants to globally extend syntax.
  863.  
  864. ----------------------------------------------------------------
  865. Subject: [2-19] How do I determine if a file is a directory or not? 
  866.                 How do I get the current directory name from within a Lisp 
  867.                 program? Is there any way to create a directory?
  868.  
  869. There is no portable way in Common Lisp of determining whether a file
  870. is a directory or not. Calling DIRECTORY on the pathname will not
  871. always work, since the directory could be empty. For UNIX systems
  872.    (defun DIRECTORY-P (pathname)
  873.       (probe-file (concatenate 'string pathname "/.")))
  874. seems to work fairly reliably. (If "foo" is a directory, then "foo/."
  875. will be a valid filename; if not, it will return NIL.) This won't, of
  876. course, work on the Macintosh, or on other operating systems (e.g.,
  877. MVS, CMS, ITS). On the Macintosh, use DIRECTORYP.
  878.  
  879. Moreover, some operating systems may not support the concept of
  880. directories, or even of a file system. For example, recent work on
  881. object-oriented technology considers files to be collections of
  882. objects. Each type of collection defines a set of methods for reading
  883. and writing the objects "stored" in the collection. 
  884.  
  885.  
  886. There's no standard function for finding the current directory from
  887. within a Lisp program, since not all Lisp environments have the
  888. concept of a current directory. Here are the commands from some Lisp
  889. implementations:
  890.    Lucid:               WORKING-DIRECTORY (which is also SETFable)
  891.                         PWD and CD also work
  892.    Allegro:             CURRENT-DIRECTORY (use excl:chdir to change it)
  893.    CMU CL:              DEFAULT-DIRECTORY
  894.    LispWorks:           LW:*CURRENT-WORKING-DIRECTORY* 
  895.                         (use LW:CHANGE-DIRECTORY to change it)
  896.  
  897. Allegro also uses the variable *default-pathname-defaults* to resolve
  898. relative pathnames, maintaining it as the current working directory.
  899. So evaluating (truename "./") in Allegro (and on certain other
  900. systems) will return a pathname for the current directory. Likewise,
  901. in some VMS systems evaluating (truename "[]") will return a pathname
  902. for the current directory.
  903.  
  904. There is no portable way of creating a new directory from within a
  905. Lisp program. 
  906.  
  907. ----------------------------------------------------------------
  908. Subject: [2-20] What is a "Lisp Machine" (LISPM)?
  909.  
  910. A Lisp machine (or LISPM) is a computer which has been optimized to run lisp
  911. efficiently and provide a good environment for programming in it. The
  912. original Lisp machines were implemented at MIT, with spinoffs as LMI (defunct)
  913. and Symbolics (bankrupt). Xerox also had a series of Lisp machines
  914. (Dandylion, Dandytiger), as did Texas Instruments (TI Explorer). The
  915. TI and Symbolics Lisp machines are currently available as cards that
  916. fit into Macintosh computers (the so-called "Lisp on a chip").
  917.  
  918. Optimizations typical of Lisp machines include:
  919.  
  920.    - Hardware Type Checking. Special type bits let the type be checked
  921.      efficiently at run-time.
  922.  
  923.    - Hardware Garbage Collection. 
  924.  
  925.    - Fast Function Calls. 
  926.  
  927.    - Efficient Representation of Lists.
  928.  
  929.    - System Software and Integrated Programming Environments.
  930.  
  931. For further information, see:
  932.  
  933.    Paul Graham, "Anatomy of a Lisp Machine", AI Expert, December 1988.
  934.  
  935.    Pleszkun and Thazhuthaveetil, "The Architecture of Lisp Machines",
  936.    IEEE Computer, March 1987.
  937.  
  938.    Ditzel, Schuler and Thomas, "A Lisp Machine Profile: Symbolics 3650",
  939.    AI Expert, January 1987.
  940.  
  941.    Peter M. Kogge, "The Architecture of Symbolic Computers",
  942.    McGraw-Hill 1991. ISBN 0-07-035596-7.
  943.  
  944. [Derived from a post by Arthur Pendragon <apendragon@delphi.com>.]
  945.  
  946. ----------------------------------------------------------------
  947. ;;; *EOF*
  948.  
  949.